package com.huobao.yunying.adapters;

import org.simple.eventbus.EventBus;

import com.huobao.yunying.entity.MyYouhuiquanHongbao;
import com.huobao.zhangying.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_MyYouhuiquanHongBao extends QuickAdapter<MyYouhuiquanHongbao> {

	private boolean isHongbao;
	public Adapter_MyYouhuiquanHongBao(Context context, boolean isHongbao) {
		super(context, R.layout.item_myyouhuiquanhongbao);
		this.isHongbao = isHongbao;
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, MyYouhuiquanHongbao arg1) {
		TextView tv_price = arg0.getView(R.id.tv_price);
		TextView tv_content = arg0.getView(R.id.tv_content);
		TextView tv_time = arg0.getView(R.id.tv_time);
		LinearLayout llyt_1 = arg0.getView(R.id.llyt_1);
		LinearLayout llyt_2 = arg0.getView(R.id.llyt_2);
		Button btn_1 = arg0.getView(R.id.btn_1);
		if(isHongbao){
			tv_price.setTextColor(Color.parseColor("#FEC164"));
			tv_price.setText("￥"+arg1.coupon_value);
			tv_content.setText("单笔满"+arg1.min_amount+"元使用\n掌婴天下");
			
			int valid = arg1.valid;
			if(valid == 0){
				btn_1.setEnabled(false);
				llyt_1.setBackgroundResource(R.mipmap.hongbao_item_bg_usered);
				llyt_2.setBackgroundResource(R.mipmap.hongbao_item_bg_used);
				tv_time.setText("有效期到\n"+arg1.end_time);
			}else{
				btn_1.setEnabled(true);
				llyt_1.setBackgroundResource(R.mipmap.hongbao_item_bg);
				llyt_2.setBackgroundResource(R.mipmap.hongbao_item_bg_right);
				tv_time.setText("有效期到\n"+arg1.end_time);
			}
		}else{
			tv_price.setTextColor(Color.parseColor("#ffffff"));
			tv_price.setText("￥"+arg1.coupon_value);
			tv_content.setText("订单满"+arg1.min_amount+"元(不含运费)\n"+arg1.store_name);
			
			int valid = arg1.valid;
			if(valid == 0){
				btn_1.setEnabled(false);
				llyt_1.setBackgroundResource(R.mipmap.youhuiquan_bg_used);
				tv_time.setText("有效期限\n"+arg1.start_time+"\n"+arg1.end_time);
			}else{
				btn_1.setEnabled(true);
				tv_time.setText("有效期限\n"+arg1.start_time+"\n"+arg1.end_time);
				llyt_1.setBackgroundResource(R.mipmap.youhuiquan_bg);
			}
		}
		
		btn_1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				EventBus.getDefault().post("", "goFristPage");
				Activity activity = (Activity) context;
				activity.finish();
			}
		});
	}

}
